# -*- coding: utf-8 -*-
"""
    Created by 杜神 at 2018/4/19
"""

import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import requests
import json
import random

key = "04d94205231d485cbde5d9c37c99d0f2"
url = "http://www.tuling123.com/openapi/api"

def turing(msg):
    payload = {'key': key, 'info': msg}
    r = requests.post(url, params=payload)
    return r.text

def rtextreplace(s):
    r = [u"喔，好难回到嗷",
       u"呃，这个真的不知道呢",
       u"真的假哒啊，好厉害的呢",
       u"亲爱哒，不要为难银家嘛",
       u"哎呀,讨厌拉~~~",
       u"是酱紫么?? 你不要骗我喔。"
       ]
    try:
        rmsg = r[random.randint(0, len(r))]
    except Exception, e:
        print e
        rmsg = r[0]
    try:
        rs = json.loads(s)
        if rs['code'] == 100000:
            rmsg = rs['text']
    except Exception, e:
        print e
    return rmsg

if __name__ == '__main__':
    print rtextreplace(turing("我喜欢你"))